Skip to content

pkg/terminal: add exit -d to detach without killing the process#4387

Open
larrasket wants to merge 1 commit into
go-delve:masterfrom
larrasket:exit-detach-without-kill
Open

pkg/terminal: add exit -d to detach without killing the process#4387
larrasket wants to merge 1 commit into
go-delve:masterfrom
larrasket:exit-detach-without-kill

Conversation

@larrasket

Copy link
Copy Markdown
Contributor

Add an exit -d flag that detaches from the target.

exitCommand records the intent on the terminal and handleExit skips the kill prompt and detaches with kill=false.

Fixes #2324

pkg/terminal/exit_test.go was generated by Claude Sonnet 5

@aarzilli aarzilli left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the use case for this? I think something like this came up before and it's actually fewer keystrokes to answer the prompt.

Comment thread pkg/terminal/exit_test.go Outdated
@@ -0,0 +1,58 @@
package terminal

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just go in terminal_test.go

Comment thread pkg/terminal/terminal.go Outdated
kill := true
if t.client.AttachedToExistingProcess() {
switch {
case t.detachNoKill:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This branch should be after the AttachedToExistingProcess check.

@larrasket

Copy link
Copy Markdown
Contributor Author

@aarzilli #2324 leaving an attached process running without answering the prompt every time is the use case. interactively yes it just saves answering n. The concrete gain is non-interactive use (for example yesno goes through liner.Prompt, which returns EOF when stdin isn't a tty, so a scripted exit on an attached process returns 2 without detaching) -d makes the detach deterministic there.

When attached to a running process, exit prompts whether to kill it. For
scripted or repetitive sessions there was no way to answer that prompt in
advance. Add an exit -d flag that detaches from the target, leaving it
running, without prompting.

exitCommand records the intent on the terminal and handleExit skips the
kill prompt and detaches with kill=false.

Fixes go-delve#2324
@larrasket larrasket force-pushed the exit-detach-without-kill branch from 04fd239 to e64c30c Compare July 6, 2026 07:31
@larrasket larrasket requested a review from aarzilli July 6, 2026 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exit from attached process without prompt

2 participants